package com.xuecheng.order.task;

import com.xuecheng.framework.domain.task.XcTask;
import com.xuecheng.order.service.XcTaskService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import org.springframework.web.client.RestTemplate;

import java.util.Calendar;
import java.util.Date;
import java.util.List;

@Component
public class ChooseCourseTask {

    private static final Logger LOGGER = LoggerFactory.getLogger(ChooseCourseTask.class);

    @Autowired
    XcTaskService xcTaskService;


    /**
     * @Description: 支付成功通过MQ发送消息
     * @Param:
     * @return:
     * @Author: Mr.Yuan
     * @Date:
     */

    @Scheduled(fixedRate = 5000)
    public void sendPaySuccess() {
//        查询一分钟以前未处理的数据
        Calendar calendar = Calendar.getInstance();
        Date date = calendar.getTime();
        int minutes = date.getMinutes();
        date.setMinutes(minutes - 1);
        List<XcTask> list = xcTaskService.findList(date, 10);
        if(list==null||list.size()==0){
          return;
        }
        for (XcTask xt : list)
        {
            if(xcTaskService.updateVersion(xt.getId(),xt.getVersion())>0){
            xcTaskService.sendSuccess(xt);
            xcTaskService.xcTaskUpdate(xt);
            }
        }

    }
}

